package xzy.Controller;

import lombok.SneakyThrows;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import xzy.dao.GradeMapper;
import xzy.pojo.Grade;
import xzy.util.JsonUtil;
import xzy.util.ResponseUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "GradeComboListServlet")
public class GradeComboListServlet extends HttpServlet {
    private static ApplicationContext context=new ClassPathXmlApplicationContext("application.xml");
    GradeMapper gradeMapper= (GradeMapper) context.getBean("gradeMapper");
    @SneakyThrows
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try{
        JSONArray jsonArray= new JSONArray();
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("id","");
        jsonObject.put("gradeName","请选择……");
        jsonArray.add(jsonObject);
        jsonArray.addAll(JsonUtil.formatRsToJsonArray(gradeMapper.getGradeAll1(null,null)));
        ResponseUtil.write(response,jsonArray);
    }catch (Exception e){
        e.printStackTrace();
    }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
